package com.nsxy.common.utils;

import java.util.Collection;

import org.springframework.data.domain.Page;

/**
 * datagrid数据
 * @author 潜行的青衣
 * @see
 */
public class DataGrid<T> {

	private long total;
	
	private Collection<T> rows;
	
	public DataGrid(Page<T> page) {
		this(page.getTotalElements(), page.getContent());
	}
	
	public DataGrid(Collection<T> rows) {
		this.rows = rows;
		this.total = rows.size();
	}
	
	public DataGrid(long total, Collection<T> rows) {
		this.rows = rows;
		this.total = total;
	}

	public static <T> DataGrid<T> newInstance(Page<T> page) {
		return new DataGrid<T>(page);
	}
	
	public static <T> DataGrid<T> newInstance(Collection<T> rows) {
		return new DataGrid<T>(rows);
	}
	
	public static <T> DataGrid<T> newInstance(long total, Collection<T> rows) {
		return new DataGrid<T>(total, rows);
	}
	
	public long getTotal() {
		return total;
	}

	public void setTotal(long total) {
		this.total = total;
	}

	public Collection<T> getRows() {
		return rows;
	}

	public void setRows(Collection<T> rows) {
		this.rows = rows;
	}
	
}
